package com.zzl.alligator.management.monitor.domain;

import com.zzl.alligator.common.constant.SystemConstants;
import com.zzl.alligator.framework.aspectj.annotation.Excel;
import com.zzl.alligator.framework.base.domain.BaseEntity;
import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.Date;


/**
 * (QrtzJobDetails)实体类
 *
 * @author zhouziliang
 * @since 2020-07-10
 */
@Data
@ToString
public class QrtzJobDetails extends BaseEntity {
    /**
     * 任务名
     */
    @NotBlank(message = "任务名不可以为空")
    @Size(min = 0, max = 190, message = "任务名长度不能超过190个字符")
    @Excel(name = "任务名")
    private String jobName;
    /**
     * 任务组
     */
    @NotBlank(message = "任务组不可以为空")
    @Size(min = 0, max = 190, message = "任务组名长度不能超过190个字符")
    @Excel(name = "任务组")
    private String jobGroup;
    /**
     * 任务描述
     */
    @Size(min = 0, max = 250, message = "描述长度不能超过250个字符")
    @Excel(name = "描述")
    private String description;
    /**
     * 执行类
     */
    @Excel(name = "执行类")
    private String jobClassName;
    /**
     * 执行方法
     */
    @Excel(name = "执行方法")
    private String jobMethodName;

    @Excel(name = "执行方法参数")
    private String jobMethodParam;
    /**
     * cron表达式
     */
    @NotBlank(message = "任务组不可以为空")
    @Size(min = 0, max = 190, message = "任务组名长度不能超过190个字符")
    @Excel(name = "cron表达式")
    private String cronExpression;
    /**
     * 执行时间
     */
    private String triggerName;
    /**
     * 任务状态
     */
    private String triggerState;
    /**
     * 任务名称 用于修改
     */
    private String oldJobName;
    /**
     * 任务分组 用于修改
     */
    private String oldJobGroup;

    /**
     * 任务启停状态
     */
    private String dealState;

    private Date nextFireTime;


    /**
     * 获取操作状态
     * @return
     */
    public String getDealState() {
        if(StringUtils.isNotBlank(dealState)) {
            return dealState;
        }
        return SystemConstants.JOB_PAUSED.equals(triggerState) ? SystemConstants.NO_FRAME : SystemConstants.NORMAL;

    }

}